package com.atguigu.userprofile.dao;

import com.atguigu.userprofile.beans.TagInfo;
import com.atguigu.userprofile.utils.MySQLUtil;

import java.util.List;

/**
 * @Classname TagInfoDao
 * @Date 2022/10/2 16:41
 * @Created by arun
 * <p>
 * 实现TagInfo的CRUD
 */
public class TagInfoDao {

    public static List<TagInfo>  selectTagInfosWithEnable(){
        String sql = " select tg.id , tg.tag_code , tg.tag_name , tg.tag_level , tg.parent_tag_id , tg.tag_type , tg.tag_value_type , tg.tag_value_limit , tg.tag_value_step , tg.tag_task_id , tg.tag_comment , tg.update_time , tg.create_time " +
                " from tag_info tg join task_info tk" +
                " on tg.tag_task_id = tk.id " +
                " where tk.task_status = '1'" ;
        List<TagInfo> tagInfos = MySQLUtil.selectList(sql, TagInfo.class, true);
        return tagInfos ;
    }

    public static TagInfo selectTagInfoByTaskId(String taskId) {
        String sql = "select id , tag_code , tag_name , tag_level , parent_tag_id , tag_type , tag_value_type , " +
                " tag_value_limit , tag_value_step , tag_task_id , tag_comment , update_time , create_time " +
                " from tag_info " +
                " where tag_task_id = " + taskId;

        TagInfo tagInfo = MySQLUtil.selectOne(sql, TagInfo.class, true);
        return tagInfo;
    }

    public static void main(String[] args) {
        TagInfo tagInfo = selectTagInfoByTaskId("1");
        System.out.println(tagInfo);
    }
}
